using System;
using aprogblog.App.MetaWeblog;
using aprogblog.App.Models;
using aprogblog.Domain;
using aprogblog.Domain.Classes;
using aprogblog.Specs.Helpers;
using FluentSpec;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace aprogblog.Specs {

    [TestClass]
    public class when_reading_an_Entry : BehaviorOf<WeblogService> {

        const string Id = Actors.TheExpectedEntryId;
        static readonly Entry TheExpectedEntry = Actors.TheExpectedEntry;
        
        [TestClass]
        public class a_WeblogService : BehaviorOf<WeblogService> {
        
            readonly Blog Blog = TestObjectFor<Blog>();
        
            [TestInitialize]
            public void SetUp() { Given.Blog = Blog; }
        
            [TestMethod]
            public void should_search_in_the_Blog() {
            
                Blog.Given().FindById(Id).WillReturn(TheExpectedEntry);
                When.GetPost(Id, null, null).ToEntry().ShouldBe(TheExpectedEntry);
            }
        }
        
        [TestClass]
        public class a_Blog : BehaviorOf<BlogClass> {
            
            [TestInitialize]
            public void SetUp() { 
                
                Given.Feed.Is(Actors.FeedWithTheExpectedEntry);
            }

            [TestMethod]
            public void should_return_it() {
                
                When.FindById(Id).ShouldBe(TheExpectedEntry);
            }

            [TestMethod]
            [ExpectedException(typeof(InvalidOperationException), 
            "contains no elements")]
            public void should_throw_exception_if_cannot_find_it() {

                When.FindById("missing id");
            }
        }
    }
}